const result = {
  key: 'login',
  login(data) {
    wx.setStorageSync(this.key, data)
  },
  logout() {
    wx.removeStorageSync(this.key)
    wx.navigateTo({
      url: '/pages/me/login/login'
    })
  },
  getData(key) {
    var data = wx.getStorageSync(this.key)

    if (key && data) {
      if (data.hasOwnProperty(key)) {
        return data[key]
      } else {
        return ''
      }
    }
    return data
  },
  hasLogin() {
    return wx.getStorageSync(this.key) ? true : false
  }
}

module.exports = result

// {code: 0,…}
//   code: 0
//   data: {user: {id: 1, username: "平静の楓", openid: "orkdl5xNZMgYN3IYu2Lc1AD_o_Mh", email: "eee@qq.com",…},…}
//     access_token: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC95ai5jb21cL2FwaVwvbG9naW4iLCJpYXQiOjE2MTcyODc0ODQsImV4cCI6MTYxNzI5MTA4NCwibmJmIjoxNjE3Mjg3NDg0LCJqdGkiOiJVSUprNWNndE9HeTdlcHVxIiwic3ViIjoxLCJwcnYiOiIyM2JkNWM4OTQ5ZjYwMGFkYjM5ZTcwMWM0MDA4NzJkYjdhNTk3NmY3Iiwicm9sZSI6InVzZXIifQ.IzxoWNzqPCBMUGOL0ty0IdevWEhw7qxcjAggYKavKZs"
//     expires_in: 3600
//     token_type: "bearer"
//     user: {id: 1, username: "平静の楓", openid: "orkdl5xNZMgYN3IYu2Lc1AD_o_Mh", email: "eee@qq.com",…}
//       agent_one: 0
//       agent_two: 0
//       avatar: "http://thirdwx.qlogo.cn/mmopen/vi_32/Mux4t3HhKvvAhv71XHunOfoNpAJnJiccicYxD3zyqw8iar4sS0pOnwSOMzP2ticCz56bpAb3tV4AoIIQIib9fHZwgibw/132"
//       balance: "0.00"
//       city: "渝中"
//       country: "中国"
//       created_at: "2021-03-02T11:24:43.000000Z"
//       email: "eee@qq.com"
//       id: 1
//       integral: 10
//       level: 1
//       login_at: "2021-03-02T11:24:46.000000Z"
//       mobile: "13662685478"
//       money: "0.00"
//       openid: "orkdl5xNZMgYN3IYu2Lc1AD_o_Mh"
//       province: "重庆"
//       sex: "男"
//       status: 1
//       username: "平静の楓"
//       msg: "登录成功，页面即将跳转..."